package com.wxx.自除数;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Jetwang
 * @date: 2022/3/23 14:49
 * @description: Solution
 * 自除数 是指可以被它包含的每一位数整除的数。
 * @version: 1.0
 */
public class Solution {
    public static List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> list = new ArrayList<>();
        for (; left <= right; left++) {
            boolean flag = true;
            int i = 0;
            int j = left;
            while (j != 0) {
                i = j % 10;
                if (i == 0 || left % i != 0) {
                    flag = false;
                    break;
                }
                j = j / 10;
            }
            if (flag) {
                list.add(left);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        List<Integer> list = selfDividingNumbers(45, 87);
        System.out.println(list);
    }
}
